#ifndef TOOLS_H
#define TOOLS_H

#include <SFML/System/Vector2.hpp>
#include <QVector2D>
#include <cmath>
#include <QPoint>

#include <iostream>
const double PI = 3.14159265358979323846;
typedef QPointF Point2D;
typedef QVector2D Vector2D;

static Vector2D turnVector(Vector2D v, double angle) {
    return Vector2D(v.x()*cos(angle) - v.y()*sin(angle), v.x()*sin(angle) - v.y()*cos(angle));
}

static double signedAngle(Vector2D v,Vector2D v2) {
    double norm = v.length() * v2.length();
    if (norm == 0) throw std::string("Division by zero");
    double cosinus = Vector2D::dotProduct(v,v2) / norm;
    double sinus = (v.x()* v2.y() + v2.x()* v.y()) / norm;
    if (sinus > 0) {
        return acos(cosinus);
    } else {
        return -acos(cosinus);
    }
}

static double signum(double d){
    if (d < 0) return -1;
    else if (d > 0) return 1;
    else return 0;
}

static Vector2D sub(Point2D position, Point2D target){
    return Vector2D(target.x()-position.x(),target.y()-position.y());
}

#endif // TOOLS_H
